package com.lams.action.archive;

import static com.lams.util.ViewParamsUtil.getParam;

import java.util.Map;

import com.lams.action.SubAction;
import com.lams.service.archive.ITeacherFacade;
import com.lams.util.ResultEntity;
import com.opensymphony.xwork2.ActionContext;

public class TeacherAction extends SubAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3218755754901579530L;
	private ITeacherFacade teacherF;
	/**
	 * 查询教师
	 * 
	 * @return
	 */
	public String query() {
		Map params = ActionContext.getContext().getParameters();
//		String qrySql = QueryUtils.getSqlBySqlCode("QUERYTEACHERS001", params);
//		List list = QueryUtils.executeQuery(this.getStart(), this.getLimit(), qrySql);
		ResultEntity result = teacherF.queryTeacher(this.getStart(), this.getLimit(), params);//new ResultEntity();
//		result.setTotalCount(list.size());
		result.setSuccess(true);
//		result.setData(list);
		result.setLimit(this.getLimit());
		result.setStart(this.getStart());
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}
	
	public String addOrUpdateTeacher() {
		Map params = ActionContext.getContext().getParameters();
		ResultEntity result = teacherF.saveOrUpdate(params);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}
	
	public String deleteTeacher() {
		ResultEntity result = new ResultEntity();
		String sql = null;
		Map params = ActionContext.getContext().getParameters();
		String teacher_id = getParam("TEACHER_ID");
		if (teacher_id == null || teacher_id.trim().equals("")) {
			result.setSuccess(true);
			result.setMessage("未选中记录");
			return SUCCESS;
		}
		boolean t = teacherF.delete(teacher_id);
//		QueryUtils.executeUpdate(sql);
		result.setMessage(t?"删除成功":"删除失败");
		result.setSuccess(t);
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public ITeacherFacade getTeacherF() {
		return teacherF;
	}

	public void setTeacherF(ITeacherFacade teacherF) {
		this.teacherF = teacherF;
	}
	

	
}
